#include<stdio.h>
#include<malloc.h>
typedef struct LNode{
	int data;
	struct LNode* next;
}LNode,*LinkList;

void out(LinkList H){
	if(H->next){
		LinkList p;
		p=H->next;
		while(p){
			printf("%d",p->data);
			if(p->next != NULL) 
            printf(" ");
			p = p->next;
		}
		printf("\n");
	}
	else printf("NULL");
}

LinkList Creat_List(){
	//尾插法
	LinkList H,node,end;
	int x;
	H = (LinkList)malloc(sizeof(LNode));
	H->next = NULL;
	end = H;
	while(scanf("%d",&x) && x!=-1){
		node = (LinkList)malloc(sizeof(LNode));
		node->next=NULL;
		
		node->data = x;
		end->next = node;
		end = node;
	}
	return H; 
}

LinkList Combine_List(LinkList A,LinkList B){
	//归并排序 
	LinkList c,p;
	c= (LinkList)malloc(sizeof(LNode));
	c->next = NULL;
	p = c;
	A = A->next;
	B = B->next;
	while(A&&B){
		if(A->data > B->data){
			p->next = B;
			B = B->next;
			p = p->next;
		}
		else{
			p->next = A;
			A = A->next;
			p = p->next;
		}
	} 
	if(A)
		p->next = A;
	if(B)
		p->next = B;
	return c;
}
int main(){
	LinkList A,B,C;
	A = Creat_List();
	B = Creat_List();
	C = Combine_List(A,B);
	out(C);
	return 0;
}
//两个有序链表序列的合并